#include "String.hpp"
#include "Color.hpp"

namespace red{
	bool StringUtils::StartsWith(const std::string &pStr, const std::string &pStart, bool pLowerCase){
		size_t strlen = pStr.length(), startlen = pStart.length();
		if(strlen < startlen || startlen == 0)
			return false;

		std::string strstart = pStr.substr(0, startlen);
		std::string str = pStr;
		if(pLowerCase){
			strstart = ToLower(strstart);
			str = ToLower(str);
		}
		return strstart == str;
	}

		// STRING StringConverter::to COLOR
		Color StringConverter::ToColor(const std::string &pVal){
			Color ret;
			StringVector vec = StringUtils::SplitString(pVal, ",");
			if(vec[0].find_first_of(".")){
				// Float Color
				if(vec.size() == 4)
					ret = Color(ToFloat(vec[0]),ToFloat(vec[1]),ToFloat(vec[2]),ToFloat(vec[3]));
				else if(vec.size() == 3)
					ret = Color(ToFloat(vec[0]),ToFloat(vec[1]),ToFloat(vec[2]), 1.f);
				else
					ret = Color::Black;
			}else{
				// Unsigned Color
				if(vec.size() == 4)
					ret = Color(ToFloat(vec[0]) / 255.f,ToFloat(vec[1]) / 255.f,ToFloat(vec[2]) / 255.f,ToFloat(vec[3]) / 255.f);
				else if(vec.size() == 3)
					ret = Color(ToFloat(vec[0]) / 255.f,ToFloat(vec[1]) / 255.f,ToFloat(vec[2]) / 255.f, 1.f);
				else
					ret = Color::Black;
			}
			return ret;
		}
}